<template>
  <div class="pass">
    <!-- 通行证管理 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>编辑密接者信息</el-breadcrumb-item>
    </el-breadcrumb>
  </div>

  <el-card>
    <div class="height">
      <el-form :label-position="labelPosition" label-width="80px">
        <el-form-item label="姓名">
          <el-input v-model="formData.uname"></el-input>
        </el-form-item>
        <el-form-item label="身份证号">
          <el-input v-model="formData.idCard"></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-select v-model="formData.gender" placeholder="请选择">
            <el-option label="男" value="男"></el-option>
            <el-option label="女" value="女"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="症状">
          <el-input v-model="formData.desc"></el-input>
        </el-form-item>
        <el-form-item label="接触来源">
          <el-input v-model="formData.comeFrom"></el-input>
        </el-form-item>

        <el-form-item label="隔离地址">
          <el-input v-model="formData.isoAddress"></el-input>
        </el-form-item>

        <el-form-item label="开始日期">
          <el-input v-model="formData.startDate"></el-input>
        </el-form-item>

        <el-form-item label="当前状态">
          <el-select v-model="formData.finished" placeholder="请选择">
            <el-option label="完成隔离" value="完成隔离"></el-option>
            <el-option label="未完成隔离" value="未完成隔离"></el-option>
          </el-select>
        </el-form-item>

        <div class="button">
          <el-form-item>
            <el-button color="red" @click="submitForm">保存</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="back">返回</el-button>
          </el-form-item>
        </div>
      </el-form>
    </div>
  </el-card>
</template>

    <script>
import { updateBaseApi,updateBaseAndTouchApi } from "../api/index1.js";
import { ElMessage } from "element-plus";
export default {
  data() {
    return {
      labelPosition: "left",
      formData: {
        baseId: "",
        comeFrom: "",
        finished: "",
        gender: "",
        idCard: "",
        isoAddress: "",
        startDate: "",
        touchId: "",
        uname: "",
        desc:''
      },
    };
  },
  mounted() {
    //隐式传递： this.$route.params.参数名！！拿到跳转过来时传递的参数 页面刷新后  不保存！！
    console.log(this.$route.params);
    this.formData = this.$route.params;
  },
  methods: {
    //返回方法
    back() {
      this.$router.push({
        path: "../views/touch", //要跳转的页面的路由
      });
    },
    //查询
    onSubmit() {
      console.log("submit!");
    },
    submitForm() {
      updateBaseAndTouchApi(this.formData).then((res) => {
        console.log(res);
        this.formData = {};
        // 2.提示用户添加成功

        if (res.code == 20000) {
          ElMessage({
            message: "更新成功",
            type: "success",
          });
        }
        this.$router.push({
          path: "../views/touch", //要跳转的页面的路由
        });
      });
    },
    //提交校验
    // submitForm(formName) {
    //     this.$refs[formName].validate((valid) => {
    //         if (valid) {
    //             alert('submit!');
    //         } else {
    //             console.log('error submit!!');
    //             return false;
    //         }
    //     });
    // },
    // resetForm(formName) {
    //     this.$refs[formName].resetFields();
    // }
  },
};
</script>

    <style lang="less" scoped>
.el-form {
  width: 800px;
}

.notice {
  margin-top: 10px;
  font-weight: bold;
}

.height {
  margin-top: 20px;
}
.height {
  line-height: 10px;
}
.el-input {
  width: 220px;
}
.el-card {
  margin-top: 10px;
}
.button {
  display: flex;
}
</style>
